<?php

namespace app\zftpay\controller;

use app\BaseController;
use app\service\webService;
use think\facade\Db;
use think\facade\View;

class Gate extends AlipayAuth
{
    public function info(){
//        $pay_status=(new webService())->getPayStatus();
//        if($pay_status=="false"){
//            return "支付商户状态异常";
//        }
        session("url",$this->getCurrentUrl().request()->url());
        $id=request()->get("id");
        $info=Db::table("community_zft_gate")->where("id",$id)->find();
        if(empty($info)){
            return "配置信息错误";
        }
        if($info["pay_status"]=="0"){
            return "支付商户状态异常";
        }
        //查询是否是黑名单用户
        $user=Db::table("zft_black_user")->where("user_id",session('user_id'))->find();
        if(!empty($user)){
            return "<text style='font-size:50px;margin: 100px'>你无权支付</text>";
        }
        View::assign("info",$info);
        $notifyurl_alipay=(new webService())->getNotifyurlAlipay();
        View::assign("notifyurl_alipay",$notifyurl_alipay);
        return View::fetch("info");
    }
    public function snMoney(){

        $key=env("APP.ZFT_KEY");
        $user=Db::table("zft_black_user")->where("user_id",session('user_id'))->find();
        if(!empty($user)){
            return "<text style='font-size:50px;margin: 100px'>你无权支付</text>";
        }
        session("url",$this->getCurrentUrl().request()->url());
        $id=request()->get("id");
        $sn=request()->get("sn");
        $money=request()->get("money");
        //$sign=request()->get("sign");
        $str="id=".$id."&sn=".$sn."&money=".$money;
        $sign=md5($key.$str.$key);
        if($sign!=request()->get("sign")){
            return "<text style='font-size:50px;margin: 100px'>支付错误,请重新支付</text>";
        }
        if (!is_numeric($money)) {
            return "<text style='font-size:50px;margin: 100px'>支付金额错误</text>";
        }
        if ($money>50) {
            return "<text style='font-size:50px;margin: 100px'>支付金额不能超过50元</text>";
        }

        $info=Db::table("community_zft_gate")->where("id",$id)->find();
        if(empty($info)){
            return "<text style='font-size:50px;margin: 100px'>配置信息错误</text>";
        }
        if($info["pay_status"]=="0"){
            return "<text style='font-size:50px;margin: 100px'>支付商户状态异常</text>";
        }
        View::assign("money",$money);
        View::assign("info",$info);
        View::assign("sn",$sn);
        $notifyurl_alipay=(new webService())->getNotifyurlAlipay();
        View::assign("notifyurl_alipay",$notifyurl_alipay);
        return View::fetch("sn_money");
    }

}